<template>
    <div>
        <!-- 55555/ -->
        <el-dialog :title="myDialog.title" :visible.sync="myDialog.flag" width="70%">
            {{changedata}}
            <el-form :model="cate">
                <el-form-item label="分类名称" label-width="80px">
                    <el-input v-model="cate.cat_name" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="活动区域" label-width="80px">
                    <el-cascader v-model="value" :options="options" :props="props" ></el-cascader>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="myDialog.flag = false">取 消</el-button>
                <el-button type="primary" @click="add">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import { addCate , editCate} from '@/utils/cate/categoryapi'
export default {
    props: {
        myDialog: Object,
        cate: Object,
        options:Array,
        props:Object,
        changedata:Array,
        editId: Number,
        value:Array,
        props: Object,
    },
    methods: {
        async add() {
            // alert('哈哈')
            if (this.myDialog.type == "add") {
                console.log(this.cate);
                if(this.changedata.length==0){
                    this.cate.cat_pid=0
                }else{
                    this.cate.cat_pid=this.changedata[this.changedata.length-1]
                }
                this.cate.cat_level = this.changedata.length;
                let res = await addCate(this.cate);
                if (res.meta.status == 201) {
                    this.$message.success(res.meta.msg);
                    this.$emit('getList');
                    this.close();
                }
            } else if (this.myDialog.type == 'edit') {
                // alert(111);
                // console.log(this.editId);
                // console.log(this.cateAdd.cat_name)
                let res = await editCate(this.editId, { cat_name: this.cate.cat_name });
                if (res.meta.status == 200) {
                    this.$message.success(res.meta.msg);
                    this.$emit('getList');
                    this.close();
                } else {
                    this.$message.error(res.meta.msg);
                }
            }
        },
        /* 关闭模态框 */
        close() {
            this.myDialog.flag = false;
        }
    }
}
</script>